<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>重设密码</title>
		<meta name="decorator" content="default" />
		<script type="text/javascript">
		$(function() {

			if("${error}"!=''){
				alertx("${error}");
				$("#sjhm").val("${sjhm}");
				$("#password").val("${password}");
				$("#repassword").val("${password}");
				$("#dxyzm").val("${dxyzm}");
			}
			
			$.validator.setDefaults({
				submitHandler : function(form) {
					form.submit();
				}
			});
			
			// 手机号码验证
			jQuery.validator.addMethod("isMobile", function(value, element) {
				var length = value.length;
				var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
				return this.optional(element) || (length == 11 && mobile.test(value));
			}, "请正确填写您的手机号码");
			
			// 开始验证
			$('#modpassForm').validate({

				rules : {
					sjhm : {
						required : true,
						isMobile : true
					},
					password : {
						required : true,
						minlength : 8
					},
					repassword : {
						required : true,
						minlength : 8,
						equalTo : "#password"
					},
					dxyzm: "required"
				},

				messages : {
					sjhm : {
						required : "请输入手机号码",
						isMobile : "请输入一个有效的手机号码"
					},
					password : {
						required : "请输入密码",
						minlength : "密码不能小于8个字符"
					},
					repassword : {
						required : "请输入确认密码",
						minlength : "确认密码不能小于8个字符",
						equalTo : "两次输入密码不一致不一致"
					},
					dxyzm: "短信验证码必须输入"
				},

				focusInvalid : false,
				onkeyup : false
			});
			
			$("#btnSubmit").click(function() {
				$("#modpassForm").submit();
			});
			
			$("#btngetyzm").click(function() {
				if($("#sjhm").val()!=''){
					$.ajax({
						url:'${ctx}/getyzm?sjhm='+$("#sjhm").val()+'&yzmyt=2',
						type: 'post',
						data:{},
						cache:false,
						dataType:'json',
						success: function(data){
							if(data.flag==1){
								$.jBox.tip('验证码已经发送');							
							}
							else{
								$.jBox.tip(data.message, 'error');
							}
						},
						error: function(){}
					});
				}
				else{
					$.jBox.tip('请输入手机号码', 'error');
					$("#sjhm").focus();
				}
				return false;
			});
		})

		</script>
	</head>
	<body>
		<div class="zhmm_contentbox">
			<h3>修改密码</h3>
			<form id="modpassForm" method="post" action="${ctx }/my/modpass">
			<div class="zhmm_downbox">
				<div class="zhmm_zh clearfix">
					<label class="tel_num">手机号：</label>
					<input class="tel_text" type="text" value="${sjhm}" id="sjhm" name="sjhm" placeholder="请输入手机号" />
				</div>
				<div class="zhmm_zh clearfix">
					<label class="tel_num">短信验证码：</label>
					<input style="width: 159px;" class="tel_text" type="text" id="dxyzm" name="dxyzm" placeholder="请输入验证码" />
					<button class="yh_btn" id="btngetyzm">获取验证码</button>
				</div>
				<div class="zhmm_zh clearfix">
					<label class="tel_num">新密码：</label>
					<input class="tel_text" type="password" id="password" name="password"/>
				</div>
				<div class="zhmm_zh clearfix">
					<label class="tel_num">确认密码：</label>
					<input class="tel_text" type="password" id="repassword" name="repassword"/>
				</div>
				<div class="zhmm_zh clearfix">
					<label class="tel_num"></label>
					<button class="xyb_btn" id="btnSubmit">保存</button>
				</div>
			</div>
			</form>
		</div>
	</body>
</html>